#!/usr/bin/python
# -*- coding: UTF-8 -*-


from monitor.base import MonitorBase
from monitor.process_monitor import ProcessMonitor
from config.config import (
    PROCESSES_MONITOR,
    COMMON_INTERVALTIME,
    PROCESSES_PID_FILES,
)
from utils.log.log import Log


log = Log("processes monitor ")


class ProcessesMonitor(MonitorBase):
    """ProcessesMonitor 进程集中监控"""

    def __init__(self):
        super(ProcessesMonitor, self).__init__(COMMON_INTERVALTIME)
        self.processes = []

        """def Init(self):"""

    def Init(self):
        log.Debug("enter processes init")
        for key, value in PROCESSES_MONITOR.items():
            log.Debug("key", key, "value=", value)
            self.processes.append(
                ProcessMonitor(
                    desc=key, name=value.get("name"), number=value.get("number")
                )
            )
        for key, value in PROCESSES_PID_FILES.items():
            log.Debug("key", key, "value=", value)
            self.processes.append(
                ProcessMonitor(
                    desc=key, name=value.get("name"), pid_file=value.get("pid_file")
                )
            )
        # 再初始化一下
        for pro in self.processes:
            pro.Init()

        """def Check(self):"""

    def Check(self):
        for pro in self.processes:
            pro.Check()
